use QLK
--Quan ly user--
create proc sp_InsertUsers
	@user varchar(15),
	@pass varchar(15),
	@status varchar(10)
as
	insert into login values(@user, @pass, @status)
--------------------------------------------------
go
Create proc sp_Updatelogin
	@user varchar(15),
	@pass varchar(15),
	@status varchar(10)
as
	update login set Usename = @user, Password = @pass, Status = @status where Usename=@user
------------------------------------------------------------------------
go
create proc sp_DelUser
	@user varchar(15)
as
	Delete from login where Usename like @user
-------------------------------------------------
create proc changePass
	@user varchar(15),
	@pass varchar(15)
as
	update login
set
	Password = @pass,
	Usename = @user
where
	Usename = @user	
---------------------------------------------------
create proc sp_getAllAcount
as
	select * from login
---------------------------------------------------
create proc sp_getpass
	@pass varchar(15)
as
	select * from login where [Password] like @pass
---------------------------------------------------
create proc sp_getuser
	@user varchar(15)
as
	select * from login where Usename like @user
---------------------------------------------------
create proc sp_getstatus
	@status varchar(10)
as
	select Status from login where Status like @status

---------------- ChungLoai-------------------------

Create proc sp_InsertChungLoai
	@MaCL varchar(20),
	@TenCL nvarchar(25)
as
	insert into ChungLoai values(@MaCL,@TenCL)
----------------------------------------------
Create proc sp_getMaCL
	@MaCL varchar(20)
as
	select * from ChungLoai where MaCL=@MaCL
----------------------------------------------
Create proc sp_UpdateChungLoai
	@MaCL varchar(20),
	@TenCL nvarchar(25)
as 
	update ChungLoai set MaCL=@MaCL,TenCL=@TenCL where MaCL=@MaCL
------------------------------------------------------------------
Create proc sp_DelChungLoai
	@MaCL varchar(20)
as
	delete from ChungLoai where MaCL=@MaCL
-------------------------------------------
Create proc sp_getAllChungLoai
as
	select * from ChungLoai

-------------Nha Cung Cap-------------------------
create proc sp_getAllNCC
as
	select * from NCC
go
create proc sp_getMaNCC
	@MaNCC varchar(10)
as
	select * from NCC where MaNCC like @MaNCC
go
create proc sp_getTenNCC
	@TenNCC varchar(25)
as
	select * from NCC where TenNCC like @TenNCC
go
create proc sp_InsertNCC
	@MaNCC varchar(10),
	@TenNCC varchar(25),
	@diachi varchar(50),
	@Mst varchar(10),
	@Sotk varchar(10)
as
	insert into NCC values(@MaNCC, @TenNCC, @diachi, @Mst, @Sotk)
go

create proc sp_UpdateNCC
	@MaNCC varchar(10),
	@TenNCC varchar(25),
	@diachi varchar(50),
	@Mst varchar(10),
	@Sotk varchar(10)
as
	update NCC
set
	MaNCC = @MaNCC, TenNCC = @TenNCC, DiaChi = @diachi, Masothue = @Mst, SoTK = @Sotk where MaNCC=@MaNCC

go
create proc sp_DelNCC
	@MaNCC varchar(10)
as
	delete from NCC where MaNCC like @MaNCC

-------Hang Hoa--------------------------------
create proc sp_insertHang
	@mahang varchar(10),
	@tenhang varchar(25),
	@chungloai varchar(20),
	@dongia float,
	@dvtinh varchar(5),
	@HSD varchar(30),
	@soluong int
as 
	insert into HangHoa values (@mahang,@tenhang,@chungloai,@dongia,@dvtinh,@HSD,@soluong)
------------------------------------------------------------------------------------------
create proc sp_getAllHangHoa
as
	select * from HangHoa
-----------------------------
create proc sp_getMaHang
	@Mahang varchar(10)
as
	select * from HangHoa where MaHang like @MaHang
----------------------------------
create proc sp_getTenHang
	@TenHang varchar(25)
as
	select * from HangHoa where TenHang like @TenHang
--------------------------------------------------
create proc sp_getChungLoai1
	@ChungLoai varchar(25)
as
	select * from HangHoa where ChungLoai like @ChungLoai
----------------------------------------------------------
drop proc sp_updateHangHoa
Create proc sp_updateHangHoa
	@mahang varchar(10),
	@tenhang varchar(25),
	@chungloai varchar(20),
	@dongia float,
	@dvtinh varchar(5),
	@HSD varchar(30),
	@soluong int
as
	update HangHoa
set
	MaHang=@mahang,TenHang=@tenhang,ChungLoai=@chungloai,DVtinh=@dvtinh,HSD=@HSD,Soluong=@soluong,DonGia = @dongia where MaHang like @mahang
----------------
Create proc sp_insertHangHoa
	@mahang varchar(10),
	@tenhang varchar(25),
	@chungloai varchar(20),
	@dongia float,
	@dvtinh varchar(5),
	@HSD varchar(30),
	@soluong int
as
insert into HangHoa values(@mahang,@tenhang,@chungloai,@dongia,@dvtinh,@HSD,@soluong)

go
--------------
drop proc sp_DellHangHoa
create proc sp_DellHangHoa
@mahang varchar(10)
as
delete from HangHoa where MaHang like @mahang
------------------------------------------------------------
Create proc sp_getAllKho
as
	select * from Kho
--
go
Create proc sp_InsertKho
	@MaKho varchar(10),
	@TenKho varchar(20),
	@DiaChi nvarchar(40)
as
	Insert into Kho values(@MaKHo,@TenKho,@DiaChi)
--
go
Create proc sp_UpdateKho
	@MaKho varchar(10),
	@TenKho varchar(20),
	@DiaChi nvarchar(40)
as
	Update Kho set TenKho=@TenKho, DiaChi=@DiaChi where MaKho=@MaKho
--
go
Create proc sp_DelKho
	@MaKho varchar(10)
as
	Delete Kho where MaKho=@MaKho
go
---------------------------------phieu xuat----------------------------------------------
create proc sp_getAllPhieuX
as
	select * from PhieuXuat
go
create proc sp_InsertPhieuX
	@sophieu int,
	@mahang varchar(10),
	@ngayx varchar(10),
	@slx int,
	@makh varchar(10)
as
	insert into PhieuXuat values(@mahang, @sophieu, @ngayx, @slx, @makh)
go
create proc sp_UpdatePhieuX
	@mahang varchar(10),
	@sophieu varchar(10),
	@slx int,
	@ngayxuat varchar(10),
	@makh varchar(10)
as
	update PhieuXuat
set
	MaHang = @mahang,
	SoPhieu = @sophieu,
	NgayXuat = @ngayxuat,
	SoLuongXuat = @slx,
	MaKH = @makh
where Sophieu = @sophieu
go
create proc sp_DelPhieuX
	@sophieu int
as
	delete from PhieuXuat where SoPhieu = @sophieu
go






